package com.boot.security.server.controller.mffl.LwyerPersonalService;

import com.boot.security.server.dao.mffl.MfflLwyerPersonalServiceDao;
import com.boot.security.server.model.mffl.MfflLwyerPersonalService;
import com.boot.security.server.model.mffl.MfflService;
import com.boot.security.server.page.table.PageTableHandler;
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
import com.boot.security.server.page.table.PageTableRequest;
import com.boot.security.server.page.table.PageTableResponse;
import com.boot.security.server.utils.mffl.ReturnBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import com.boot.security.server.service.impl.mffl.LwyerPersonalService.LwyerPersonalService;

import java.util.List;

@Api(tags = "律师设置收费标准")
@RestController
@RequestMapping("/lawyer/mfflLwyerpersonalservices")
public class Lawyer_MfflLwyerPersonalServiceController {

    @Autowired
    private MfflLwyerPersonalServiceDao mfflLwyerPersonalServiceDao;

    //律师个人收费标准
    @Autowired
    private LwyerPersonalService LwyerPersonalService;


    @GetMapping(value = "getservicelist")
    @ApiOperation(value="获取可以设置金额的项目")
    public ReturnBean<MfflService> getServiceList(){
        return LwyerPersonalService.getServiceList();
    }


    @GetMapping(value = "/{id}")
    @ApiOperation(value="获取要设置服务的信息 注：如果返回的money为空代表律师没有设置这项服务的收费")
    public ReturnBean<MfflService> getServiceinfo(@ApiParam(name = "id", value = "要设置服务的id",required = true) @PathVariable Integer id){
        if (id == null) {
            return new ReturnBean("201","id不能为空");
        }
        return LwyerPersonalService.getServiceinfo(id);
    }

    @PutMapping(value = "putservicemoeny")
    @ApiOperation(value="设置服务收费金额")
    public ReturnBean<MfflService> putServiceMoeny(@ApiParam(name = "id", value = "要设置服务的id",required = true) @RequestParam Integer id,
                                                   @ApiParam(name = "money", value = "金额/元",required = true) @RequestParam Integer money){
        if (id == null) {
            return new ReturnBean("201","id不能为空");
        }
        if (id == null) {
            return new ReturnBean("201","money不能为空");
        }

        return LwyerPersonalService.putServiceMoeny(id,(double)money);
    }



  /*  @PostMapping
    @ApiOperation(value = "保存")
    public MfflLwyerPersonalService save(@RequestBody MfflLwyerPersonalService mfflLwyerPersonalService) {
        mfflLwyerPersonalServiceDao.save(mfflLwyerPersonalService);

        return mfflLwyerPersonalService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public MfflLwyerPersonalService get(@PathVariable Long id) {
        return mfflLwyerPersonalServiceDao.getById(id);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public MfflLwyerPersonalService update(@RequestBody MfflLwyerPersonalService mfflLwyerPersonalService) {
        mfflLwyerPersonalServiceDao.update(mfflLwyerPersonalService);

        return mfflLwyerPersonalService;
    }

    @GetMapping
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return mfflLwyerPersonalServiceDao.count(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<MfflLwyerPersonalService> list(PageTableRequest request) {
                return mfflLwyerPersonalServiceDao.list(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public void delete(@PathVariable Long id) {
        mfflLwyerPersonalServiceDao.delete(id);
    }*/
}
